<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    canvas {
      border: 1px solid #000;
    }
  </style>
</head>

<body>
  <canvas width="600" height="400"></canvas>
</body>
<script>
  let canvas = document.querySelector("canvas")
  let ctx = canvas.getContext("2d")

  ctx.beginPath()       //路径开始
  ctx.moveTo(0, 0)      //抬起笔，移动
  ctx.moveTo(100, 100)       //
  ctx.lineTo(200, 200)    //落下笔，绘制
  ctx.lineTo(200, 100)
  // ctx.lineTo(100,100)
  ctx.closePath()       //路径闭合

  //描边
  ctx.strokeStyle = "red"     //描边颜色
  ctx.lineWidth = 10        //描边宽度
  ctx.stroke()          //描边

  //填充
  ctx.fillStyle = "yellowgreen"     //填充颜色
  ctx.fill()                //填充
</script>

</html>